/*
 * User: rant
 * Date: Aug 6, 2007
 *
 *
 */
package laMalinche.propertyChangeAdapters.model;

import laMalinche.testingPlayGround.testModel.VOEntity;
import laMalinche.testingPlayGround.testModel.ChangeListener;

import java.beans.PropertyChangeEvent;

/**
 *
 */
public class VOEntityImp implements VOEntity {
    final PropertyChangeObservable objeect;
    private final String property;

    public VOEntityImp(final PropertyChangeEvent event) {
        objeect = (PropertyChangeObservable) event.getSource();
        property = event.getPropertyName();
    }

    public void addChangeListener(ChangeListener changeListener) {
        objeect.addPropertyChangeListener(property, new ChangeListenerTOPCHangeListener(changeListener));
    }

    public void removeChangeListener(ChangeListener changeListener) {
        objeect.removePropertyChangeListener(property, new ChangeListenerTOPCHangeListener(changeListener));
    }

	public String getOgnl() {
//        String ognl = ((OgnlHolder) objeect).getOgnl();
//        if(ognl != "")
//        ognl = ognl +".";
//        return ognl  +property ;
         return getOgnl((OgnlHolder) objeect,property);
    }

    public static String getOgnl(OgnlHolder ognlHolder, String propertyName){
         String ognl = ognlHolder.getOgnl();
        if(ognl != "")
        ognl = ognl +".";
        return ognl  +propertyName;

    }

    public Object getValue() {
		return null;
	}

    public String getGeneralizeOgnl() {
        return generalizeLists(getOgnl());
    }

        private String generalizeLists(String ognl) {
        String regex = "\\.[0-9]+\\.";
        String s = ognl.replaceAll(regex, "\\.");
        return s;
    }
}